﻿using MiniExcelLibs;
using Newtonsoft.Json;
using PanhuaWin.WMS2NC888;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PanhuaWin.工厂.仓库.下线
{
    public partial class Form仓库转移 : UIPage
    {
        public Form仓库转移()
        {
            InitializeComponent();
        }

        private void uiButton选择文件_Click(object sender, EventArgs e)
        {
            string path;
            openFileDialog1.RestoreDirectory = true;

            this.openFileDialog1.Filter = "Excel 文件(*.xlsx)|*.xlsx";
            if (this.openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                path = this.openFileDialog1.FileName;
                DataTable table = (DataTable)MiniExcel.QueryAsDataTable(path, useHeaderRow: true);
                if (table != null && table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        string 生产批号 = table.Rows[i]["生产批号"].ToString();
                        string 移入仓库 = table.Rows[i]["移入仓库"].ToString();
                        ExternalSystemToNcItfPortTypeClient client = new ExternalSystemToNcItfPortTypeClient();
                        var a = new
                        {
                            region = "华东",
                            vbatchcode = 生产批号,
                            cWarehouseName = 移入仓库
                        };
                        string jsonStr = JsonConvert.SerializeObject(a);
                        string responseStr = client.updateFinishedProductsInBill(jsonStr);
                        NCModel.NCResponseModel nCResponse = JsonConvert.DeserializeObject<NCModel.NCResponseModel>(responseStr);
                        if (nCResponse != null && nCResponse.state == 0)
                        {
                            table.Rows[i]["结果"] = nCResponse.msg;
                        }
                        else
                        {
                            table.Rows[i]["结果"] = nCResponse.msg;
                        }
                    }
                }

                uiDataGridView1.DataSource = table;
                uiDataGridView1.Refresh();
            }
        }
    }
}
